/**
 * Created by plter on 2016/10/27.
 */

(function () {

    function sayHello(userNameOrUser, age) {
        switch (arguments.length) {
            case 2:
                console.log(`Hello ${userNameOrUser},and age is ${age}`);
                break;
            case 1:
                switch (typeof userNameOrUser) {
                    case "string":
                        console.log(`Hello ${userNameOrUser}`);
                        break;
                    case "object":
                        if (userNameOrUser) {
                            console.log(`Hello ${userNameOrUser.name},and age is ${userNameOrUser.age}`);
                        } else {
                            throw new Error("参数错误");
                        }
                        break;
                }
                break;
            default:
                throw new Error("参数错误");
        }
    }

    // sayHello("ucai",10);
    sayHello({name: "ucai", age: 10});

})();